home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / anivga12 / example2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-07-11  |  1.9 KB  |  74 lines

  1. {$A+,B-,D+,L+,N-,E-,O-,R-,S-,V-,G-,F-,I-,X-}
  2. {$M 16384,0,655360}
  3. PROGRAM Example2;
  4.  
  5. {Demonstrates using scrolling backgrounds}
  6.  
  7. USES ANIVGA,CRT;
  8. CONST TileName='tile2.COD';    {4 simple tiles}
  9.       SpriteName='flower.COD';
  10.       ch:Char=#0;
  11. VAR i,j:Integer;
  12.     temp:WORD;
  13.     collide:BOOLEAN;
  14.  
  15. PROCEDURE Init;
  16. BEGIN
  17.  XTiles:=0; YTiles:=0;
  18.  SetBackgroundMode(scrolling);
  19.  SetOffscreenTile(3);
  20.  SetBackgroundScrollRange(-500,-500,100,100);
  21.  
  22.  {paste tiles into this background, using circular enumeration 0,1,2,3,0,...}
  23.  MakeTileArea(0,2,2);
  24.  
  25.  {Set SPRITEAD[10]:}
  26.  IF loadSprite(SpriteName,10)=0
  27.   THEN BEGIN
  28.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  29.        END;
  30. END;
  31.  
  32. BEGIN
  33.  Init;
  34.  InitGraph;
  35.  temp:=LoadTile(TileName,0); {load the 4 tiles & give them the numbers 0..3}
  36.  IF Error<>Err_None
  37.   THEN BEGIN
  38.         CloseRoutines;
  39.         WRITELN('Couldn''t access file '+TileName+' : '+GetErrorMessage);
  40.         halt(1)
  41.        END;
  42.  
  43.  SetCycleTime(0); {animation as fast as possible}
  44.  
  45.  SpriteN[0]:=10; SpriteX[0]:=0;   SpriteY[0]:=0;
  46.  SpriteN[5]:=10; SpriteX[5]:=100; SpriteY[5]:=100;
  47.  
  48.  WHILE keypressed DO ch:=readkey;
  49.  Animate;
  50.  REPEAT
  51.   collide:=Hitdetect(0,5);
  52.   IF collide THEN BEGIN sound(1000); delay(5); nosound END;
  53.   if KeyPressed
  54.    THEN BEGIN
  55.          WHILE KeyPressed DO ch:=Upcase(ReadKey);
  56.          CASE ch OF
  57.           'I':dec(SpriteY[0]);  {change position of sprite with I,J,K,M}
  58.           'J':dec(SpriteX[0]);
  59.           'K':inc(SpriteX[0]);
  60.           'M':inc(SpriteY[0]);
  61.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  62.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  63.           'D':inc(StartVirtualX,10);
  64.           'X':inc(StartVirtualY,10);
  65.          END;
  66.          IF POS(ch,'IJKMESDX')>0 THEN Animate;
  67.         END;
  68.  
  69.  UNTIL (ch='Q') OR (ch=#27);  {"Q" or ESC to quit}
  70.  
  71.  CloseRoutines;
  72.  
  73. END.
  74.